<template>
    <Modal
            class-name="vertical-center-modal"
            v-model="modal"
            :width="45"
            :title="head_title">
        <div class="row"  v-if="modal">
            <div class="col-lg-12">
                <i-checkbox-group v-model="select">
                    <i-checkbox class="m-r-md" v-for='item in list' :label="item.id" :key="item.id">{{item.name}}</i-checkbox>
                </i-checkbox-group>
            </div>
        </div>
        <div slot="footer">
            <button class="btn btn-danger" type="button" @click='cancel'>取消</Button>
            <btn-submit class="btn btn-success" type="submit" :p-click="ok">确定</btn-submit>
        </div>
    </Modal>
</template>
<script>
    import serConference from '../../serves/api-conference'
    const setDataDef = {
        parent_id:"",
        title:"",
        address:"",
        start_at:"",
    };
    export default{
        props:{

        },
        data () {
            return {
                modal:false,
                info:{},
                list:[],
                select:[],
            }
        },
        computed:{
            cDate(){
                return [this.info.start_at,this.info.end_at]
            },
            head_title(){
                return '分活动管理员设置'
            },
        },
        methods: {
            async handleOpen(data){
                this.info = Object.assign({},setDataDef,data);
                this.$set(this,'modal',true);
                this.init()
            },
            async init(){
              let res = await serConference.getChildrenManager({mee_id:this.info.id});
              if(res.code==1){
                  this.list=res.data||[];
                  let a = [];
                  this.list.forEach((v,i)=>{
                      if(v.is == 1){
                          a.push(v.id)
                      }
                  });
                  this.select=a;
              }else {
                  this.$Message.error(res.message)
              }
            },
            cancel () {
                this.$emit('on-change',false);
                this.$set(this,'modal',false);
            },
            async ok () {
                if(this.select.length==0){
                    this.$Message.warning('请至少选择一个分会管理人员');
                    return false
                }
                let res = await serConference.setChildrenManager({
                    mee_id:this.info.id,
                    ids:this.select
                });
                if(res.code==1){
                    this.$Message.success(res.message);
                    this.$emit('on-change',true);
                    this.$set(this,'modal',false);
                    return true;
                }else{
                    this.$Message.error(res.message);
                    return false;
                }
            },
        },
        components:{
        }
    }
</script>